<?php

namespace app\dao\setting\admin;

use app\dao\BaseDao;
use app\model\setting\admin\SystemRole;
use think\db\Where;

class SystemRoleDao extends BaseDao
{

    public function create(array $where)
    {
        return  $this -> getModel()::create($where);

    }

    public function index(array $where)
    {
        return $this -> search() ->withoutField(['update_time']) ->order('weight','asc') -> paginate($where['pageSize']);
    }

    public function updateDao(array $where)
    {
        return $this -> search() -> where('id',$where['id']) ->where('website_id',$where['website_id']) -> update($where);
    }

    public function deleteDao(array $where)
    {
        return $this -> search() -> destroy($where['id']);
    }

    /**
     * 搜索器
     * @param $query
     * @param $where
     * @return void
     */
    public function searchTitleAttr( $query,  $where)
    {
        if($where['title']){
            $query -> whereLike('title','%' . $where['title'] . '%') ;
        }
    }

    public function searchTitle( $where)
    {
        return $this -> getModel() -> where('title','like','%' . $where['title'] . '%') -> paginate($where['pageSize']);
    }

    protected function setModel(): string
    {
        return SystemRole::class;
    }
}